<!doctype html>
<html lang="en" class="no-js">
  <head>
    <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="generator" content="Hugo 0.68.3" />

<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">



<link rel="shortcut icon" href="/favicons/favicon.ico" >
<link rel="apple-touch-icon" href="/kustomize/favicons/apple-touch-icon-180x180.png" sizes="180x180">
<link rel="icon" type="image/png" href="/kustomize/favicons/favicon-16x16.png" sizes="16x16">
<link rel="icon" type="image/png" href="/kustomize/favicons/favicon-32x32.png" sizes="32x32">
<link rel="icon" type="image/png" href="/kustomize/favicons/android-36x36.png" sizes="36x36">
<link rel="icon" type="image/png" href="/kustomize/favicons/android-48x48.png" sizes="48x48">
<link rel="icon" type="image/png" href="/kustomize/favicons/android-72x72.png" sizes="72x72">
<link rel="icon" type="image/png" href="/kustomize/favicons/android-96x96.png" sizes="96x96">
<link rel="icon" type="image/png" href="/kustomize/favicons/android-144x144.png" sizes="144x144">
<link rel="icon" type="image/png" href="/kustomize/favicons/android-192x192.png" sizes="192x192">

<title>Exec plugin on linux | Kustomize</title><meta property="og:title" content="Exec plugin on linux" />
<meta property="og:description" content="Exec plugin on linux in 60 seconds
" />
<meta property="og:type" content="article" />
<meta property="og:url" content="https://kubernetes-sigs.github.io/kustomize/guides/plugins/execpluginguidedexample/" />
<meta property="article:modified_time" content="2020-07-16T12:57:18-07:00" /><meta property="og:site_name" content="Kustomize" />
<meta itemprop="name" content="Exec plugin on linux">
<meta itemprop="description" content="Exec plugin on linux in 60 seconds
">
<meta itemprop="dateModified" content="2020-07-16T12:57:18-07:00" />
<meta itemprop="wordCount" content="465">



<meta itemprop="keywords" content="" /><meta name="twitter:card" content="summary"/>
<meta name="twitter:title" content="Exec plugin on linux"/>
<meta name="twitter:description" content="Exec plugin on linux in 60 seconds
"/>





<link rel="preload" href="/kustomize/scss/main.min.818a933df0186c907f1faea6730835dd5fa01c3b53af36bb68396dc80a2d3c45.css" as="style">
<link href="/kustomize/scss/main.min.818a933df0186c907f1faea6730835dd5fa01c3b53af36bb68396dc80a2d3c45.css" rel="stylesheet" integrity="">


<script
  src="https://code.jquery.com/jquery-3.3.1.min.js"
  integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
  crossorigin="anonymous"></script>



<link rel="stylesheet" type="text/css" href="https://kubernetes-sigs.github.io/kustomize//css/asciinema-player.css" />

    <title>Exec plugin on linux | Kustomize</title>
  </head>
  <body class="td-page">
    <header>
      
<nav class="js-navbar-scroll navbar navbar-expand navbar-dark flex-column flex-md-row td-navbar">
        <a class="navbar-brand" href="/kustomize/">
		<span class="navbar-logo"></span><span class="text-uppercase font-weight-bold">Kustomize</span>
	</a>
	<div class="td-navbar-nav-scroll ml-md-auto" id="main_navbar">
		<ul class="navbar-nav mt-2 mt-lg-0">
			
			
			<li class="nav-item mr-4 mb-2 mb-lg-0">
				
				
				
				
				
				
				<a class="nav-link" href="/kustomize/installation/" ><span>Installation</span></a>
			</li>
			
			<li class="nav-item mr-4 mb-2 mb-lg-0">
				
				
				
				
				
				
				<a class="nav-link active" href="/kustomize/guides/" ><span class="active">Guides</span></a>
			</li>
			
			<li class="nav-item mr-4 mb-2 mb-lg-0">
				
				
				
				
				
				
				<a class="nav-link" href="/kustomize/api-reference/" ><span>API Reference</span></a>
			</li>
			
			<li class="nav-item mr-4 mb-2 mb-lg-0">
				
				
				
				
				<a class="nav-link" href="https://github.com/kubernetes-sigs/kustomize/tree/master/examples" target="_blank" ><span>Example</span></a>
			</li>
			
			<li class="nav-item mr-4 mb-2 mb-lg-0">
				
				
				
				
				
				
				<a class="nav-link" href="/kustomize/faq/" ><span>FAQ</span></a>
			</li>
			
			<li class="nav-item mr-4 mb-2 mb-lg-0">
				
				
				
				
				
				
				<a class="nav-link" href="/kustomize/blog/" ><span>Blog</span></a>
			</li>
			
			<li class="nav-item mr-4 mb-2 mb-lg-0">
				
				
				
				
				
				
				<a class="nav-link" href="/kustomize/contributing/" ><span>Contributing</span></a>
			</li>
			
			
			
			<li class="nav-item dropdown d-none d-lg-block">
				

<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
	English
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
	
	<a class="dropdown-item" href="/kustomize/zh/guides/plugins/execpluginguidedexample/">简体中文</a>
	
</div>
			</li>
			
		</ul>
	</div>
	<div class="navbar-nav d-none d-lg-block">
</div>
</nav>

    </header>
    <div class="container-fluid td-outer">
      <div class="td-main">
        <div class="row flex-xl-nowrap">
          <div class="col-12 col-md-3 col-xl-2 td-sidebar d-print-none">
            




<div id="td-sidebar-menu" class="td-sidebar__inner">
  
  <form class="td-sidebar__search d-flex align-items-center">
    

    <button class="btn btn-link td-sidebar__toggle d-md-none p-0 ml-3 fas fa-bars" type="button" data-toggle="collapse" data-target="#td-section-nav" aria-controls="td-docs-nav" aria-expanded="false" aria-label="Toggle section navigation">
    </button>
  </form>
  
  <nav class="collapse td-sidebar-nav pt-2 pl-4" id="td-section-nav">
    
    <div class="nav-item dropdown d-block d-lg-none">
      

<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
	English
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
	
	<a class="dropdown-item" href="/kustomize/zh/guides/plugins/execpluginguidedexample/">简体中文</a>
	
</div>
    </div>
    
    






<ul class="td-sidebar-nav__section pr-md-3">
  <li class="td-sidebar-nav__section-title">
    <a  href="/kustomize/guides/" class="align-left pl-0 pr-2 td-sidebar-link td-sidebar-link__section">Guides</a>
  </li>
  <ul>
    <li class="collapse show" id="kustomizeguides">
      
      
      
      
      






<ul class="td-sidebar-nav__section pr-md-3">
  <li class="td-sidebar-nav__section-title">
    <a  href="/kustomize/guides/bespoke/" class="align-left pl-0 pr-2 collapsed td-sidebar-link td-sidebar-link__section">Bespoke Application</a>
  </li>
  <ul>
    <li class="collapse " id="kustomizeguidesbespoke">
      
      
      
    </li>
  </ul>
</ul>

      
      
      
      






<ul class="td-sidebar-nav__section pr-md-3">
  <li class="td-sidebar-nav__section-title">
    <a  href="/kustomize/guides/offtheshelf/" class="align-left pl-0 pr-2 collapsed td-sidebar-link td-sidebar-link__section">Off The Shelf Application</a>
  </li>
  <ul>
    <li class="collapse " id="kustomizeguidesofftheshelf">
      
      
      
    </li>
  </ul>
</ul>

      
      
      
      






<ul class="td-sidebar-nav__section pr-md-3">
  <li class="td-sidebar-nav__section-title">
    <a  href="/kustomize/guides/plugins/" class="align-left pl-0 pr-2 active td-sidebar-link td-sidebar-link__section">Kustomize Plugins</a>
  </li>
  <ul>
    <li class="collapse show" id="kustomizeguidesplugins">
      
      
      
      
      
      
      <a class="td-sidebar-link td-sidebar-link__page " id="m-kustomizeguidespluginsbuiltins" href="/kustomize/guides/plugins/builtins/">Builtin Plugins</a>
      
      
      
      
      
      <a class="td-sidebar-link td-sidebar-link__page  active" id="m-kustomizeguidespluginsexecpluginguidedexample" href="/kustomize/guides/plugins/execpluginguidedexample/">Exec plugin on linux</a>
      
      
      
      
      
      <a class="td-sidebar-link td-sidebar-link__page " id="m-kustomizeguidespluginsgoplugincaveats" href="/kustomize/guides/plugins/goplugincaveats/">Go plugin Caveats</a>
      
      
      
      
      
      <a class="td-sidebar-link td-sidebar-link__page " id="m-kustomizeguidespluginsgopluginguidedexample" href="/kustomize/guides/plugins/gopluginguidedexample/">Go plugin example</a>
      
      
    </li>
  </ul>
</ul>

      
      
      
      






<ul class="td-sidebar-nav__section pr-md-3">
  <li class="td-sidebar-nav__section-title">
    <a  href="/kustomize/guides/components/" class="align-left pl-0 pr-2 collapsed td-sidebar-link td-sidebar-link__section">Kustomize Components</a>
  </li>
  <ul>
    <li class="collapse " id="kustomizeguidescomponents">
      
      
      
    </li>
  </ul>
</ul>

      
      
    </li>
  </ul>
</ul>

  </nav>
</div>




          </div>
          <div class="d-none d-xl-block col-xl-2 td-toc d-print-none">
            






<div class="td-page-meta ml-2 pb-1 pt-2 mb-0">





<a href="https://github.com/kubernetes-sigs/kustomize/edit/master/site/content/en/guides/plugins/execPluginGuidedExample.md" target="_blank"><i class="fa fa-edit fa-fw"></i> Edit this page</a>
<a href="https://github.com/kubernetes-sigs/kustomize/issues/new?title=Exec%20plugin%20on%20linux" target="_blank"><i class="fab fa-github fa-fw"></i> Create documentation issue</a>


<a href="https://github.com/kubernetes-sigs/kustomize/issues/new" target="_blank"><i class="fas fa-tasks fa-fw"></i> Create project issue</a>

</div>






<nav id="TableOfContents">
  <ul>
    <li>
      <ul>
        <li></li>
      </ul>
    </li>
    <li><a href="#make-a-place-to-work">Make a place to work</a></li>
    <li><a href="#create-a-kustomization">Create a kustomization</a></li>
    <li><a href="#make-a-home-for-plugins">Make a home for plugins</a></li>
    <li><a href="#create-the-plugin">Create the plugin</a></li>
    <li><a href="#install-kustomize">Install kustomize</a></li>
    <li><a href="#review-the-layout">Review the layout</a></li>
    <li><a href="#build-your-app-using-the-plugin">Build your app, using the plugin</a></li>
  </ul>
</nav>



          </div>
          <main class="col-12 col-md-9 col-xl-8 pl-md-5" role="main">
            
  

            <nav aria-label="breadcrumb" class="d-none d-md-block d-print-none">
	<ol class="breadcrumb spb-1">
		










<li class="breadcrumb-item" >
	<a href="https://kubernetes-sigs.github.io/kustomize/guides/">Guides</a>
</li>




<li class="breadcrumb-item" >
	<a href="https://kubernetes-sigs.github.io/kustomize/guides/plugins/">Kustomize Plugins</a>
</li>




<li class="breadcrumb-item active" aria-current="page">
	<a href="https://kubernetes-sigs.github.io/kustomize/guides/plugins/execpluginguidedexample/">Exec plugin on linux</a>
</li>

	</ol>
</nav	>

            
<div class="td-content">
	<h1>Exec plugin on linux</h1>
	<div class="lead">Exec plugin on linux in 60 seconds</div>
	<p>This is a (no reading allowed!) 60 second copy/paste guided
example.  Full plugin docs <a href="..">here</a>.</p>
<p>This demo writes and uses a somewhat ridiculous
<em>exec</em> plugin (written in bash) that generates a
<code>ConfigMap</code>.</p>
<p>This is a guide to try it without damaging your
current setup.</p>
<h4 id="requirements">requirements</h4>
<ul>
<li>linux, git, curl, Go 1.13</li>
</ul>
<h2 id="make-a-place-to-work">Make a place to work</h2>
<pre><code>DEMO=$(mktemp -d)
</code></pre><h2 id="create-a-kustomization">Create a kustomization</h2>
<p>Make a kustomization directory to
hold all your config:</p>
<pre><code>MYAPP=$DEMO/myapp
mkdir -p $MYAPP
</code></pre><p>Make a deployment config:</p>
<pre><code>cat &lt;&lt;'EOF' &gt;$MYAPP/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: the-deployment
spec:
  replicas: 3
  template:
    spec:
      containers:
      - name: the-container
        image: monopole/hello:1
        command: [&quot;/hello&quot;,
                  &quot;--port=8080&quot;,
                  &quot;--date=$(THE_DATE)&quot;,
                  &quot;--enableRiskyFeature=$(ENABLE_RISKY)&quot;]
        ports:
        - containerPort: 8080
        env:
        - name: THE_DATE
          valueFrom:
            configMapKeyRef:
              name: the-map
              key: today
        - name: ALT_GREETING
          valueFrom:
            configMapKeyRef:
              name: the-map
              key: altGreeting
        - name: ENABLE_RISKY
          valueFrom:
            configMapKeyRef:
              name: the-map
              key: enableRisky
EOF
</code></pre><p>Make a service config:</p>
<pre><code>cat &lt;&lt;EOF &gt;$MYAPP/service.yaml
kind: Service
apiVersion: v1
metadata:
  name: the-service
spec:
  type: LoadBalancer
  ports:
  - protocol: TCP
    port: 8666
    targetPort: 8080
EOF
</code></pre><p>Now make a config file for the plugin
you&rsquo;re about to write.</p>
<p>This config file is just another k8s resource
object.  The values of its <code>apiVersion</code> and <code>kind</code>
fields are used to <em>find</em> the plugin code on your
filesystem (more on this later).</p>
<pre><code>cat &lt;&lt;'EOF' &gt;$MYAPP/cmGenerator.yaml
apiVersion: myDevOpsTeam
kind: SillyConfigMapGenerator
metadata:
  name: whatever
argsOneLiner: Bienvenue true
EOF
</code></pre><p>Finally, make a kustomization file
referencing all of the above:</p>
<pre><code>cat &lt;&lt;EOF &gt;$MYAPP/kustomization.yaml
commonLabels:
  app: hello
resources:
- deployment.yaml
- service.yaml
generators:
- cmGenerator.yaml
EOF
</code></pre><p>Review the files</p>
<pre><code>ls -C1 $MYAPP
</code></pre><h2 id="make-a-home-for-plugins">Make a home for plugins</h2>
<p>Plugins must live in a particular place for
kustomize to find them.</p>
<p>This demo will use the ephemeral directory:</p>
<pre><code>PLUGIN_ROOT=$DEMO/kustomize/plugin
</code></pre><p>The plugin config defined above in
<code>$MYAPP/cmGenerator.yaml</code> specifies:</p>
<blockquote>
<pre><code>apiVersion: myDevOpsTeam
kind: SillyConfigMapGenerator
</code></pre></blockquote>
<p>This means the plugin must live in a directory
named:</p>
<pre><code>MY_PLUGIN_DIR=$PLUGIN_ROOT/myDevOpsTeam/sillyconfigmapgenerator

mkdir -p $MY_PLUGIN_DIR
</code></pre><p>The directory name is the plugin config&rsquo;s
<em>apiVersion</em> followed by its lower-cased <em>kind</em>.</p>
<p>A plugin gets its own directory to hold itself,
its tests and any supplemental data files it
might need.</p>
<h2 id="create-the-plugin">Create the plugin</h2>
<p>There are two kinds of plugins, <em>exec</em> and <em>Go</em>.</p>
<p>Make an <em>exec</em> plugin, installing it to the
correct directory and file name.  The file name
must match the plugin&rsquo;s <em>kind</em> (in this case,
<code>SillyConfigMapGenerator</code>):</p>
<pre><code>cat &lt;&lt;'EOF' &gt;$MY_PLUGIN_DIR/SillyConfigMapGenerator
#!/bin/bash
# Skip the config file name argument.
shift
today=`date +%F`
echo &quot;
kind: ConfigMap
apiVersion: v1
metadata:
  name: the-map
data:
  today: $today
  altGreeting: &quot;$1&quot;
  enableRisky: &quot;$2&quot;
&quot;
EOF
</code></pre><p>By definition, an <em>exec</em> plugin must be executable:</p>
<pre><code>chmod a+x $MY_PLUGIN_DIR/SillyConfigMapGenerator
</code></pre><h2 id="install-kustomize">Install kustomize</h2>
<p>Per the <a href="/kustomize/installation">instructions</a>:</p>
<pre><code>curl -s &quot;https://raw.githubusercontent.com/\
kubernetes-sigs/kustomize/master/hack/install_kustomize.sh&quot;  | bash
mkdir -p $DEMO/bin
mv kustomize $DEMO/bin
</code></pre><h2 id="review-the-layout">Review the layout</h2>
<pre><code>tree $DEMO
</code></pre><h2 id="build-your-app-using-the-plugin">Build your app, using the plugin</h2>
<pre><code>XDG_CONFIG_HOME=$DEMO $DEMO/bin/kustomize build --enable_alpha_plugins $MYAPP
</code></pre><p>Above, if you had set</p>
<blockquote>
<pre><code>PLUGIN_ROOT=$HOME/.config/kustomize/plugin
</code></pre></blockquote>
<p>there would be no need to use <code>XDG_CONFIG_HOME</code> in the
<em>kustomize</em> command above.</p>

	
	
	<div class="text-muted mt-5 pt-3 border-top">Last modified July 16, 2020: <a  href="https://github.com/kubernetes-sigs/kustomize/commit/f9ee578aed600136133c3232fff03029cdfc526e">Docs: Auto-fix markdownlint issues (f9ee578a)</a>
</div>
</div>


          </main>
        </div>
      </div>
      
<footer class="bg-dark py-5 row d-print-none">
  <div class="container-fluid mx-sm-5">
    <div class="row">
      <div class="col-6 col-sm-4 text-xs-center order-sm-2">
        
        
        
<ul class="list-inline mb-0">
  
  <li class="list-inline-item mx-2 h3" data-toggle="tooltip" data-placement="top" title="User mailing list" aria-label="User mailing list">
    <a class="text-white" target="_blank" href="https://groups.google.com/forum/#!forum/kubernetes-sig-cli">
      <i class="fa fa-envelope"></i>
    </a>
  </li>
  
</ul>

        
        
      </div>
      <div class="col-6 col-sm-4 text-right text-xs-center order-sm-3">
        
        
        
<ul class="list-inline mb-0">
  
  <li class="list-inline-item mx-2 h3" data-toggle="tooltip" data-placement="top" title="GitHub" aria-label="GitHub">
    <a class="text-white" target="_blank" href="https://github.com/kubernetes-sigs/kustomize">
      <i class="fab fa-github"></i>
    </a>
  </li>
  
</ul>

        
        
      </div>
      <div class="col-12 col-sm-4 text-center py-2 order-sm-2">
        <small class="text-white">&copy; 2020 Kubernetes Authors All Rights Reserved</small>
        
	
		
	
      </div>
    </div>
  </div>
</footer>


    </div>
    
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>







<script src="/kustomize/js/main.min.35b203b3c2114e187f6e4bbf0903c511aaaac5535186321e3b5e364656b6de0c.js" integrity="sha256-NbIDs8IRThh/bku/CQPFEaqqxVNRhjIeO142Rla23gw=" crossorigin="anonymous"></script>



<script src="https://kubernetes-sigs.github.io/kustomize//js/asciinema-player.js"></script>


  </body>
</html>